#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from typing import List
from pydantic import BaseModel, Field
from ndmp.comm.const import SubJobType


class PermissionInfo(BaseModel):
    user: str = Field(default='root', description='user')
    group: str = Field(default='root', description='group')
    file_mode: str = Field(default='0700', description='mod', alias='fileMode')


class ResultInfo(BaseModel):
    code: int = Field(default=0, description='执行结果')
    bodyErr: int = Field(default=0, description='错误码')
    message: str = Field(default='unknow reason', description='erro message')
    bodyErrParams: list = Field(None, description="错误码具体参数")
    exception: dict = Field(None, description='exception', alias='exception')


class Resource(BaseModel):
    id: str = Field(default=None, description='id')
    name: str = Field(default=None, description='name')
    type: str = Field(default='NDMP', description='type')
    sub_type: str = Field(default='NDMP-BackupSet', description='subType', alias='subType')
    parent_id: str = Field(default=None, description='parentId', alias='parentId')
    parent_name: str = Field(default=None, description='parentName', alias='parentName')
    extend_info: dict = Field(None, description='extend_info', alias='extendInfo')


class ListAppV2Response(BaseModel):
    resource_list: List[Resource] = Field(default=[], description='resource list', alias='resourceList')
    page_no: int = Field(default=0, description='页号', alias='pageNo')
    pages: int = Field(default=1, description='总页数')
    page_size: int = Field(default=200, description='页大小', alias='pageSize')
    total: int = Field(default=0, description='总大小')


class SubJob(BaseModel):
    job_id: str = Field(default='', description='任务ID', alias='jobId')
    sub_job_id: str = Field(default='', description='子任务ID', alias='subJobId')
    job_type: int = Field(default=SubJobType.BUSINESS_SUB_JOB.value, description='任务类型', alias='jobType')
    job_name: str = Field(default='', description='任务名', alias='jobName')
    job_priority: int = Field(default=1, description='任务优先级', alias='jobPriority')
    policy: int = Field(default=0, description='策略')
    ignore_failed: bool = Field(default=False, description='是否忽略失败结果', alias='ignoreFailed')
    exec_node_id: str = Field(default='', description='执行任务节点ID', alias='execNodeId')
    job_info: str = Field(default='', description='任务信息', alias='jobInfo')


class TaskStats(BaseModel):
    copy_size: int = Field(default=0, description='拷贝字节大小', alias='copySize')
    start_time: int = Field(default=0, description='开始任务的时间戳', alias='startTime')
    file_cnt: int = Field(default=0, description='已备份文件数', alias='fileCnt')


class RestoreTaskStats(BaseModel):
    restore_size: int = Field(default=0, description='已恢复字节大小', alias='restoreSize')
    start_time: int = Field(default=0, description='开始任务的时间戳', alias='startTime')
    file_cnt: int = Field(default=0, description='已恢复文件数', alias='fileCnt')
